package com.ruoyi.project.WebMoudle.WxUser.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.WebMoudle.WxUser.domain.WxUser;
import com.ruoyi.project.WebMoudle.WxUser.service.IWxUserService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 微信用户Controller
 * 
 * @author ruoyi
 * @date 2020-06-22
 */
@Controller
@RequestMapping("/WxUser/WxUser")
public class WxUserController extends BaseController
{
    private String prefix = "WxUser/WxUser";

    @Autowired
    private IWxUserService wxUserService;

    @RequiresPermissions("WxUser:WxUser:view")
    @GetMapping()
    public String WxUser()
    {
        return prefix + "/WxUser";
    }

    /*请求支付密码*/
    @RequiresPermissions("WxUser:WxUser:editPayNumber")
    @GetMapping("/resetPayNum/{wxUserId}")
    public String resetPayNum(@PathVariable("wxUserId") Long wxUserId, ModelMap mmap){
        WxUser wxUser = wxUserService.selectWxUserById(wxUserId);
        mmap.put("oldPayNumber", wxUser.getPayNumber());
        mmap.put("wxUserId", wxUserId);
        return prefix + "/resetPayNum";
    }

    /*重置支付密码*/
    @RequiresPermissions("WxUser:WxUser:editPayNumber")
    @PostMapping("/resetPayNum")
    public AjaxResult resetPayNum(WxUser wxUser){

        return toAjax(wxUserService.updateWxUser(wxUser));
    }

    /**
     * 查询微信用户列表
     */
    @RequiresPermissions("WxUser:WxUser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WxUser wxUser)
    {
        startPage();
        List<WxUser> list = wxUserService.selectWxUserList(wxUser);
        return getDataTable(list);
    }

    /**
     * 导出微信用户列表
     */
    @RequiresPermissions("WxUser:WxUser:export")
    @Log(title = "微信用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WxUser wxUser)
    {
        List<WxUser> list = wxUserService.selectWxUserList(wxUser);
        ExcelUtil<WxUser> util = new ExcelUtil<WxUser>(WxUser.class);
        return util.exportExcel(list, "WxUser");
    }

    /**
     * 新增微信用户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存微信用户
     */
    @RequiresPermissions("WxUser:WxUser:add")
    @Log(title = "微信用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WxUser wxUser)
    {
        return toAjax(wxUserService.insertWxUser(wxUser));
    }

    /**
     * 修改微信用户
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WxUser wxUser = wxUserService.selectWxUserById(id);
        mmap.put("wxUser", wxUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存微信用户
     */
    @RequiresPermissions("WxUser:WxUser:edit")
    @Log(title = "微信用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WxUser wxUser)
    {
        return toAjax(wxUserService.updateWxUser(wxUser));
    }

    /**
     * 删除微信用户
     */
    @RequiresPermissions("WxUser:WxUser:remove")
    @Log(title = "微信用户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wxUserService.deleteWxUserByIds(ids));
    }

    /**
     * 修改会员归属平台
     */
    @RequiresPermissions("WxUser:WxUser:edit")
    @Log(title = "微信用户", businessType = BusinessType.UPDATE)
    @PostMapping("/changeTerrace")
    @ResponseBody
    public AjaxResult changeTerrace(Long wxUserId)
    {
        return toAjax(wxUserService.changeTerrace(wxUserId));
    }

    /**
     * 修改会员归属商家
     */
    @RequiresPermissions("WxUser:WxUser:edit")
    @Log(title = "微信用户", businessType = BusinessType.UPDATE)
    @PostMapping("/changeBelongShop")
    @ResponseBody
    public AjaxResult changeBelongShop(Long wxUserId,Long shopId)
    {
        return toAjax(wxUserService.changeBelongShop(wxUserId,shopId));
    }

    @RequiresPermissions("WxUser:WxUser:edit")
    @GetMapping("/selectShop/{wxUserId}")
    public String selectShop(@PathVariable("wxUserId")Long wxUserId,ModelMap mmap)
    {
        mmap.put("wxUserId",wxUserId);
        return prefix + "/selectShop";
    }

    /**
     * 增加会员积分
     */
    @RequiresPermissions("WxUser:WxUser:edit")
    @Log(title = "微信用户", businessType = BusinessType.UPDATE)
    @PostMapping("/toAddJF")
    @ResponseBody
    public AjaxResult toAddJF(Long wxUserId,Integer JfNum)
    {
        return toAjax(wxUserService.toAddJF(wxUserId,JfNum));
    }
}
